﻿package com.powerunion.extjs.utils;

import java.io.File;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.newsoft.excelimp.DbImportServ;
import com.newsoft.excelimp.IParaSetServ;
import com.newsoft.excelimp.UpLoadFileProcMain;
import com.newsoft.xrinsur.insurunitnew.business.PersonModiDbImportServ;
import com.newsoft.xrinsur.insurunitnew.business.PersonModiParaSetServ;
import com.newsoft.xrinsur.townperson.business.NewInsurPersonDbImportServ;
import com.newsoft.xrinsur.townperson.business.NewInsurPersonParaSetServ;
import com.newsoft.xrinsur.townperson.business.TownPersonDbImportServ;
import com.newsoft.xrinsur.townperson.business.TownPersonParaSetServ;

public class Upload extends HttpServlet {
	private String uploadPath = "C:\\upload\\"; // 用于存放上传文件的目录
	private String tempPath = "C:\\upload\\tmp\\"; // 用于存放临时文件的目录

	public void init() throws ServletException {
		uploadPath = this.getInitParameter("uploadPath");
		tempPath = this.getInitParameter("tempPath");
		// 文件夹不存在就自动创建：
		if (!new File(uploadPath).isDirectory())
			new File(uploadPath).mkdirs();
		if (!new File(tempPath).isDirectory())
			new File(tempPath).mkdirs();
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		String modulename = request.getParameter("modulename");
		System.out.println("modulename="+modulename);
		UpLoadFileProcMain main = new UpLoadFileProcMain(uploadPath, tempPath, request, response);
		IParaSetServ paraserv = null;
		DbImportServ dbimpserv = null;
		if ("personmodi".equals(modulename)) {
			paraserv = new PersonModiParaSetServ();
			dbimpserv = new PersonModiDbImportServ();
			main.run(paraserv,dbimpserv);			
		} else if ("townperson".equals(modulename)) {
			paraserv = new TownPersonParaSetServ();
			dbimpserv = new TownPersonDbImportServ();
			main.run(paraserv,dbimpserv);
		} else if ("newinsurperson".equals(modulename)) {
			paraserv = new NewInsurPersonParaSetServ();
			dbimpserv = new NewInsurPersonDbImportServ();
			main.run(paraserv,dbimpserv);
		}
	}
	
	public static void main(String[] args){
	}
}
